package com.generation.tool.controller;

import com.generation.tool.pojo.result.R;
import org.springframework.web.bind.annotation.*;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import com.generation.tool.pojo.po.User;
import com.generation.tool.service.IUserService;

/**
 * @Author: 吃我一钊
 * @Description: 用户表控制层
 * @Date: 2025/01/27
 */
@RestController
@RequestMapping("/user")
public class UserController {

	@Autowired
	private IUserService userService;

	/**
	 * 新增数据
	 * @param user
	 * @return
	 */
	@PostMapping("/save")
	public R<Void> save(@RequestBody User user) {
		userService.save(user);
		return R.ok();
	}

	/**
	 * 根据id删除
	 * @param userId
	 * @return
	 */
	@DeleteMapping("/deleteById/{userId}")
	public R<Void> deleteById(@PathVariable("userId") Integer userId) {
		userService.removeById(userId);
		return R.ok();
	}

	/**
	 * 根据id修改数据
	 * @param user
	 * @return
	 */
	@PutMapping("/updateById")
	public R<Void> updateById(@RequestBody User user) {
		userService.updateById(user);
		return R.ok();
	}

	/**
	 * 根据id查询数据
	 * @param userId
	 * @return
	 */
	@GetMapping("/getById/{userId}")
	public R<User> getById(@PathVariable("userId") Integer userId) {
		User user = userService.getById(userId);
		return R.ok(user);
	}
	/**
	 * 查询所有数据
	 * @return
	 */
	@GetMapping("/list")
	public R<List<User>> list() {
		List<User> userList = userService.list();
		return R.ok(userList);
	}

}